package com.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

/**
 * @author Tsing
 * 统一返回类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApiResult<Y> {
    private Integer code;
    private String msg;
    private Y Data;



    public static  <Y> ApiResult<Y> success(Integer code, String msg, Y data){
        return new ApiResult<Y>(code,msg,data);
    }

    public static <Y> ApiResult<Y> success(){
        return new ApiResult<>(HttpStatus.OK.value(),"操作成功",null);
    }

    public static  <Y> ApiResult<Y> success( Y data){
        return new ApiResult<Y>(HttpStatus.OK.value(),"操作成功",data);
    }

    public static <Y> ApiResult<Y> fail(Integer code, String msg){
        return new ApiResult<>(code,msg,null);
    }
}
